//
//  STBarButtonItem.swift
//  STVVeibo
//
//  Created by leergou on 16/7/19.
//  Copyright © 2016年 WhiteHouse. All rights reserved.
//

import UIKit

class STBarButtonItem: UIBarButtonItem {
    
    // 重载构造函数
     init(title: String?, imgName: String?, target: AnyObject, action: Selector) {
        super.init()

        let button = UIButton()
        // 根据传进来的参数判定 是设置 标题 还是 图片
        if let tit = title {
            button.setTitle(tit, forState: UIControlState.Normal)
            button.setTitleColor(ThemeColor, forState: UIControlState.Normal)
            button.setTitleColor(UIColor.grayColor(), forState: UIControlState.Disabled)
            button.titleLabel?.font = UIFont.systemFontOfSize(14)
        }
        
        if let img = imgName {
            button.setImage(UIImage(named: img), forState: UIControlState.Normal)
        }
        
        // 给 button 添加点击事件
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        button.sizeToFit()
        self.customView = button
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
